#pragma once
#include <QObject>
#include <qjsonvalue.h>
#include "HiFileTransferDef.h"

class HiFileReceiverServer;
class HiFileSender;
class HiFileTransfer : public QObject
{
    Q_OBJECT
public:
    explicit HiFileTransfer(QObject* parent = nullptr);
    ~HiFileTransfer();

public:
    void setSavePaths(const QStringList& paths);
    void setMinRemainSize(qint64 size);
    bool startReceiverServer(int port);

    void sendFiles(const QString& ip, const QList<HiFileTransferDef::sFile>& files);
    void stop(const QString& ip);
    void stopAll ();

signals:
    void signalSendError(const QString& ip, const QString& error);
    void signalSendChanged(const QString& ip, const HiFileTransferDef::sFile& file);
    void signalSendFinished(const QString& ip, const HiFileTransferDef::sFile& file);
    void signalSendPrograss(const QString& ip, const qint64 totalSize, const qint64 size);
    void signalSendAllFinished(const QString& ip);
    void signalSendStop(const QString& ip);

    void signalReceiveDataSize(const QString& ip, const qint64 nSize);
    void signalFileReceiveFinished(const QString& ip, const QString& filePath, const QByteArray& userData);
    void signalReceiveStart(const QString& ip);
    void signalReceiveError(const QString& ip, HiFileTransferDef::eRecevieError);

private:
    HiFileReceiverServer* mReceiverServer = nullptr;
    QMap<QString, HiFileSender*> mIpAndSenderMap;
};